<template>
  <view class="login-password p-4">
    <u-form ref="form1" label-width="160rpx">
      <u-form-item label="用户名">
          <u-input v-model="form.username" placeholder="请输入" />
      </u-form-item>
      <u-form-item label="密码">
          <u-input v-model="form.password" placeholder="请输入" type="password" />
      </u-form-item>
    </u-form>
    <view class="mt-[40rpx]">
      <u-button class="btn-cyan-gradient" shape="circle" :loading="btnLoading" @click="submitForm"> 登录 </u-button>
      <view class="p-4 c-grey9 text-center" @click="proxy.$util.gotoPage('/pages/register/index')">没账号？去注册</view>
    </view>
  </view>
</template>
<script setup lang="ts">
import { useAppStore } from '@/stores/app';
const appStore = useAppStore();
const {proxy} = getCurrentInstance() as ComponentInternalInstance;
let btnLoading = ref(false);
let form = reactive({
  username: '',
  password: '',//'Bookclub88888888',
});
const verifyForm = () => {
    if(!proxy.$verify.null(form.username, '请输入用户名')){
        return false;
    }
    if(!proxy.$verify.null(form.password, '请输入密码')){
        return false;
    }
    return true;
};
const submitForm = () => {
    if(!verifyForm()){
        return;
    }
    appStore.accountLogin(form).then(res => {
        let url = uni.getStorageSync('beforeLogin');
        if(url){
            uni.reLaunch({
                url: url
            });
        }else{
            uni.reLaunch({
                url: '/pages/home/index'
            })
        }
    }).catch(err => {
        console.log(err);
    });
}
</script> 